package com.example.dangjianbanner203zw2021606130.slice;

import com.example.dangjianbanner203zw2021606130.MainAbility;
import com.example.dangjianbanner203zw2021606130.ResourceTable;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.window.dialog.ToastDialog;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MainAbilitySlice extends AbilitySlice {
    Banner banner;
    List<String> title= new ArrayList<>();
    List<Integer>list=new ArrayList<>();

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        banner= (Banner) findComponentById(ResourceTable.Id_main_banner);
        list.add(ResourceTable.Media_dj1);
        list.add(ResourceTable.Media_dj2);
        list.add(ResourceTable.Media_dj3);
        list.add(ResourceTable.Media_dj4);
        list.add(ResourceTable.Media_dj5);
        list.add(ResourceTable.Media_dj6);

        title.add(" 永远跟党走");
        title.add(" 习主席讲话");
        title.add(" 党建学习");
        title.add(" 不忘初心，牢记使命");
        title.add(" 党建活动");
        title.add(" 党员主题日");
        banner.setBannerTitles(title);
        banner.setImages(list);
        banner.setBannerStyle(60);
        banner.setDelayTime(3000);
        banner.setScaleType(1);
        banner.setTitleTextSize(16);
        try {
            banner.start();
        } catch (NotExistException e) {
            e.printStackTrace();
        } catch (WrongTypeException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int i) {
                switch (i){
                    case 0:
                        new ToastDialog(MainAbilitySlice.this).setText("永远跟党走").show();
                        break;
                    case 1:
                        new ToastDialog(MainAbilitySlice.this).setText("习主席讲话").show();
                        break;
                    case 2:
                        new ToastDialog(MainAbilitySlice.this).setText("党建学习").show();
                        break;
                    case 3:
                        new ToastDialog(MainAbilitySlice.this).setText("不忘初心，牢记使命").show();
                        break;
                    case 4:
                        new ToastDialog(MainAbilitySlice.this).setText("党建活动").show();
                        break;
                    case 5:
                        new ToastDialog(MainAbilitySlice.this).setText("党员主题日").show();
                        break;
                }
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
